import i18n from './config/i18n'
require('dotenv').config()
// console.log('====',process.env)
export default {
  loading: {
    color: '#fa524c',
    height: '2px'
  },
  server: {
    port: 3002, // default: 3000
    host: '0.0.0.0' // 本地需要测试pwa的话，改成localhost,
    // host: 'localhost',
  },
  env: {
    baseUrl: process.env.BASE_URL,
    APP_ENV: process.env.APP_ENV
  },
  router: {
    middleware: ['refreshToken']
  },
  // pwa: {
  //   icon: {
  //     source: "/icon.png",
  //     fileName: 'icon.png'
  //   },
  //   manifest: {
  //     name: process.env.APP_SHORT_NAME,
  //     short_name: process.env.APP_SHORT_NAME,
  //     lang: 'zh-CN',
  //     theme_color: '#fff',
  //     description: process.env.APP_DESCRIPTION,
  //     display: 'standalone',
  //     scope: '/'
  //   }
  //   // workbox: {
  //   //   dev: process.env.APP_ENV === 'local' || !process.env.APP_ENV
  //   // }
  // },
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: process.env.APP_NAME,
    // htmlAttrs: {
    //   lang: 'zh'
    // },
    meta: [
      { charset: 'utf-8' },
      { hid: 'index', name: process.env.APP_NAME, content: process.env.APP_KEYWORD },
      { hid: 'author', name: 'author', content: 'www.wwwww.com' },
      { name: 'viewport', content: 'width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' },
      { hid: 'description', name: 'description', content: process.env.APP_DESCRIPTION },
      { hid: 'keywords', name: 'keywords', content: process.env.APP_KEYWORD }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
      { rel: 'shortcut icon', href: '/favicon.ico' },
      { rel: 'apple-touch-icon', href: '/favicon.ico' }
    ],
    script: [
      // { innerHtml: 'console.log(`js脚本`)' }
    ]
  },
  hooks: {},
  // Global CSS: https://go.nuxtjs.dev/config-css
  css: ['element-ui/lib/theme-chalk/index.css', '@/assets/css/main.css', '@/assets/css/iconfont.css', 'video.js/dist/video-js.css', '@/assets/css/video.css'],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: ['@/plugins/route', '@/plugins/element-ui', '@/plugins/ctx-inject.js', '@/plugins/filter.js', '@/plugins/store', '@/plugins/global', '@/plugins/vue-moment', { src: '@/plugins/videoPlayer.js', ssr: false }],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // '@nuxtjs/pwa'
  ],
  // router: {
  //   middleware: ['auth']
  // },
  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    '@nuxtjs/axios',
    // '@nuxtjs/pwa',
    // ['@nuxtjs/dotenv', { filename: '.env' }],
    ['@nuxtjs/dotenv', { filename: process.env.APP_ENV === 'local' || !process.env.APP_ENV ? '.env' : '.env.' + process.env.APP_ENV }],
    '@nuxtjs/style-resources',
    ['@nuxtjs/i18n', i18n]
  ],
  styleResources: {
    scss: './assets/css/main.scss'
  },
  configureWebpack: {
    //关闭 webpack 的性能提示
    performance: {
      hints: 'warning',
      //入口起点的最大体积
      maxEntrypointSize: 50000000,
      //生成文件的最大体积
      maxAssetSize: 30000000,
      //只给出 js 文件的性能提示
      assetFilter: function(assetFilename) {
        return assetFilename.endsWith('.js')
      }
    }
  },
  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    analyze: false,
    assetFilter: function(assetFilename) {
      return assetFilename.endsWith('.js')
    },
    optimization: {
      minimize: true,
      minimizer: [
        // new CssMinimizerPlugin(),
      ],
      splitChunks: {
        // 生成 chunk 的最小体积（以 bytes 为单位）
        chunks: 'all',
        automaticNameDelimiter: '-',
        maxSize: 102400,
        cacheGroups: {
          vendors: {
            test: /[\\/]node_modules[\\/]/,
            priority: -10, //优先级
            reuseExistingChunk: true
          },
          common: {
            minChunks: 2,
            priority: -20, //优先级
            reuseExistingChunk: true
          }
        }
      }
    },
    // 防止多次打包
    transpile: [/^element-ui/],
    // postcss: [
    //   require("postcss-px2rem-exclude")({
    //     remUnit: 192, // 之所以写192是因为设了pc最大宽度1920px
    //     exclude: "/node_modules/element-ui",
    //   }),
    // ],
    // postcss: {
    //   plugins: {
    //     'postcss-px2rem-exclude': {
    //       remUnit: 192, // 设计图为750 * height
    //       remPrecision: 2 // rem的小数点后位数
    //       //   exclude: "/node_modules/element-ui" //取消vant组件css转成rem
    //     }
    //   }
    // },
    // vendor: ['element-ui'],
    /*
     ** You can extend webpack config here
     */
    extend(config, ctx) {}
  }
}
